<template>
	<view class="box">
		<uni-nav-bar :fixed="true" :border="false" backgroundColor="#f9f2ea" :statusBar="true" leftText="创作圈"
			@clickLeft="goBack"></uni-nav-bar>
		<view class="search-box">
			<view class="search">
				<image class="img" src="../../static/search.png" mode=""></image>
				<input class="input" type="text" confirm-type="搜索" v-model="keywords" placeholder="搜索关键词"
					placeholder-style="font-size: 24rpx;color: #ccc" value="" @confirm="toSearch" />
				<view class="delete" v-if="keywords!=''">
					<image class="img" src="../../static/search_delete.png" mode="" @click="deleteSearch"></image>
				</view>
				<view class="search-line"></view>
				<view class="search-btn" @click="toSearch">
					搜索
				</view>
			</view>
		</view>
		<view class="search-mark">

		</view>
		<view class="list flex-between">
			<view class="item-box">
				<view class="item" v-for="(item, index) in dataShunt(1, artworkList)" :key="index"
					@click="toArtistDetails(item.id)">
					<view class="img-bg">
						<image class="img" :src="item.thumb" mode="aspectFit"></image>
					</view>
					<view class="content">
						<view class="content-title">
							{{item.name}}
						</view>
						<!-- <view class="price">
							价格：￥{{item.goods_price}}
						</view> -->
						<view class="dosame" @click="toDosame(item)">
							<image class="same" src="../../static/dosame.png" mode=""></image>
							<view class="">
								做同款
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="item-box">
				<view class="add" @click="toCreate">
					<image class="img" src="../../static/add_new.png" mode=""></image>
					<view class="add-right">
						<view class="">
							开始创作吧！
						</view>
						<view class="">
							Add New
						</view>
					</view>
				</view>
				<view class="item" v-for="(item, index) in dataShunt(2, artworkList)" :key="index"
					@click="toArtistDetails(item.id)">
					<view class="img-bg">
						<image class="img" :src="item.thumb" mode="aspectFit"></image>
					</view>
					<view class="content">
						<view class="content-title">
							{{item.name}}
						</view>
						<!-- <view class="price">
							价格：￥{{item.goods_price}}
						</view> -->
						<view class="dosame" @click.stop="toDosame(item)">
							<image class="same" src="../../static/dosame.png" mode=""></image>
							<view class="">
								做同款
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<FootBar></FootBar>

		<uni-load-more v-show="loadMoreShow" :status="loadMoreStatus"></uni-load-more>

	</view>
</template>

<script>
	import {
		artList
	} from "@/api/public.js"
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
	import FootBar from '@/components/footbar.vue'
	export default {
		data() {
			return {
				id: "",
				page: 1,
				loadMoreShow: false,
				loadMoreStatus: "more",
				artworkList: [],
				swiperList: [],
				keywords: "",
			}
		},
		components: {
			uniLoadMore,
			FootBar
		},
		onLoad(obj) {
			this.id = obj.id;
			this.getList();
		},
		watch: {
			keywords() {
				this.page = 1;
				this.artworkList = [];
				this.getList();
			},
		},
		methods: {
			goBack() {
				uni.navigateBack();
			},
			toSearch() {
				this.page = 1;
				this.artworkList = [];
				this.getList();
			},
			deleteSearch() {
				this.keywords = "";
				console.log(this.keywords)
			},
			navChange(type) {
				this.navChoose = type;
			},
			getList() {
				artList(this.page, this.keywords).then(res => {
		
					if (this.page == 1) {
						if (!res.reData.data || res.reData.data.length == 0) {
							this.noMoreList = true
						} else {
							this.noMoreList = false
							this.showLoadMore = true
						}
					}
					if (res.reData.data) {
						let newData = res.reData.data;
						this.artworkList = this.artworkList.concat(newData);
						if (res.reData.data.length < 10) {
							this.loadMoreStatus = 'noMore';
						} else {
							this.loadMoreStatus = 'more';
						}
					}
				})
			},
			toArtistDetails(id) {
				uni.navigateTo({
					url: "artDetails?id=" + id
				})
			},
			toDosame(item) {
				if (uni.getStorageSync("userData")) {
					uni.navigateTo({
						url: "../mine/doSame?id=" + item.id
					})
				} else {
					uni.navigateTo({
						url: "/pages/index/choose"
					})
				}
			},
			toCreate() {
				if (uni.getStorageSync("userData")) {
					uni.navigateTo({
						url: "../mine/createArtwork"
					})
				} else {
					uni.navigateTo({
						url: "/pages/index/choose"
					})
				}
			},
			// 数据分流
			dataShunt(type, arr) {
				let backArr1 = [];
				let backArr2 = [];
				for (let i in arr) {
					if (i % 2 == 0) {
						backArr1.push(arr[i])
					} else {
						backArr2.push(arr[i])
					}
				}
				if (type == 1) {
					return backArr1
				} else {
					return backArr2
				}
			}
		},
		//上拉加载
		onReachBottom() {
			this.loadMoreStatus = 'loading';
			this.showLoadMore = true
			if (this.page * 10 == this.artworkList.length) {
				this.page++
				this.getList()
			} else {
				this.loadMoreStatus = 'noMore'; //没有数据时显示‘没有更多’
			}
		},

	}
</script>

<style lang="scss" scoped>
	.search-mark {
		margin-bottom: 30rpx;
		width: 690rpx;
		height: 80rpx;
	}

	.search-box {
		position: fixed;
		z-index: 1000;
		left: 0;
		right: 0;
		padding: 30rpx 40rpx 30rpx;
		background: #f9f2ea;
	}

	.search {
		box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.07);
		width: 660rpx;
		height: 80rpx;
		background: #fffaf5;
		border-radius: 40rpx;
		padding-left: 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.img {
			position: absolute;
			width: 40rpx;
			height: 40rpx;
			margin-right: 30rpx;
		}

		.input {
			width: 480rpx;
			padding-left: 70rpx;
		}

		.delete {
			position: absolute;
			right: 140rpx;
			width: 40rpx;
			height: 40rpx;
			z-index: 10000;
			display: flex;
			justify-content: center;
			align-items: center;

			.img {
				width: 30rpx;
				height: 30rpx;
			}
		}

		.search-line {
			height: 30rpx;
			width: 2rpx;
			background-color: #e9e9e9;
		}

		.search-btn {
			width: 100rpx;
			text-align: center;
			font-size: 24rpx;
			line-height: 80rpx;
			margin-right: 20rpx;
		}
	}

	.list {
		padding: 30rpx 30rpx 0;
		margin: 0 auto;
		flex-wrap: wrap;

		.add {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 330rpx;
			height: 150rpx;
			background-color: rgba(244, 229, 196, 1);
			box-shadow: 0rpx 4rpx 8rpx rgba(230, 209, 200, 1);
			border-radius: 10rpx;
			margin-bottom: 30rpx;

			.img {
				width: 48rpx;
				height: 48rpx;
				margin-right: 30rpx;
				border-radius: 10rpx;
			}

			.add-right {
				font-size: 28rpx;
				line-height: 44rpx;
				color: rgba(129, 106, 106, 1);
			}
		}

		.item {
			width: 330rpx;
			margin-bottom: 30rpx;
			box-shadow: 0px 4px 4px rgba(189, 163, 112, 0.25);
			border-radius: 10rpx;
			overflow: hidden;
			position: relative;

			.img-bg {
				width: 330rpx;
				height: 330rpx;
				// background-image: url(../../static/art_bg.png);
				background-size: 100% 100%;
				overflow: hidden;


			}

			.img {

				width: 100%;
				height: 100%;
				// position: absolute;
				// top:-70rpx;
			}

			.content {
				background-color: #fffaf5;
				padding: 0 30rpx;

				.content-title {
					font-size: 28rpx;
					line-height: 28rpx;
					font-weight: 700;
					padding-top: 20rpx;
					color: rgba(140, 111, 111, 1);
				}

				.price {
					font-size: 24rpx;
					line-height: 24rpx;
					color: #bd313a;
				}

				.dosame {
					padding: 30rpx 0;
					display: flex;
					align-items: center;
					font-size: 28rpx;
					line-height: 28rpx;
					color: rgba(209, 188, 161, 1);

					.same {
						width: 32rpx;
						height: 32rpx;
						margin-right: 10rpx;
					}
				}
			}
		}
	}
</style>
